<?php

class SearchController extends Controller
{
	public function actionIndex()
	{
		$page = Yii::app()->request->getParam('page',null);
		$per_page = Yii::app()->request->getParam('per_page',null);
		$articles = Articles::model()->gets($per_page);
		$data = array();
		$data = array();
		foreach($articles as $key=>$article){
			
			$articleTags = $article->articleTags;
			$article->id = outStr($article->id);
			
			
			$arr = $article->attributes;
			$article->user->id = outStr($article->user->id);
			$arr['userInfo'] = $article->user->attributes;
			
			$tags = array();
			foreach($articleTags as $k=>$t){
				if(!empty($t->category)){
					$tags[] = $t->category->name;
				}
			}
			$arr['tags'] = $tags;
			
			
			
			$data[] = $arr;
		}
		
		jsonOut(array(
			'error'=>!empty($data) ? false : true,
			'data'=>$data
		));
	}
}